import { Component, Inject } from '@angular/core';
import { IonicPage, NavController } from 'ionic-angular';
import { Subscription } from "rxjs/Subscription";

/**
 * 意见反馈
 */
@IonicPage()
@Component({
  selector: 'page-feedback',
  templateUrl: 'feedback.html',
})
export class FeedbackPage {

  protected feeback: any= {
    contact: '',
    content: '',
  };
  protected authSubscription: Subscription;
  constructor(
    @Inject('auth') private authService,
    @Inject('user') private userService,
    private navCtrl: NavController,
  )
  {}

  ionViewWillEnter() {
    this.authSubscription= this.authService.getAuth()
      .subscribe(auth=>{
        this.feeback.contact= auth.login.username;
    })
  }
  /*** 页面离开
   * */
  ionViewWillLeave()
  {
    if(typeof this.authSubscription!== 'undefined')
      this.authSubscription.unsubscribe();
  }

  // 执行反馈
  executeFeedback(): void
  {
    this.userService.saveFeedback(this.feeback,this.navCtrl);
  }
}
